// 配置路由
import Vue from "vue";
import VueRouter from "vue-router";

// 使用插件
Vue.use(VueRouter);

// 引入路由组件

// 首页
import Home from "@/pages/Home"
// 搜索
import Search from "@/pages/Search"
// 登录
import Login from "@/pages/Login"
// 注册
import Register from "@/pages/Register"

// 重写 push和 replace方法
//  1、保存原有写法
let originPush = VueRouter.prototype.push;

//  2.重写 push、replace
VueRouter.prototype.push = function (location, resolve, reject) {
    if (resolve && reject) {
        originPush.call(this, location);
    } else {
        // 防止同路由传参报错
        originPush.call(this, location, () => {}, () => {});
    }
};


// 配置路由
export default new VueRouter({
    routes: [{
            path: '/home',
            component: Home,
            meta: {
                showFooter: true
            }
        }, {
            name: 'search',
            path: '/search',
            component: Search,
            meta: {
                showFooter: true
            }
        }, {
            path: '/login',
            component: Login,
            meta: {
                showFooter: false
            }

        }, {
            path: '/register',
            component: Register,
            meta: {
                showFooter: false
            }

        },
        // 重定向到首页
        {
            path: '*',
            redirect: '/home',
        }
    ]
});